

// 正式ip
// var shopIp = http://web.51adsign.com

var flag =0;
// 测试ip
var shopIp = 'http://wangtongweb.51adsign.com';//flag==1?"http://web.biaoshi360.cn":"http://testweb.biaoshi360.cn";
var imgIp = "http://cdnimg1.51adsign.com/"
var commonIp = "http://app.51adsign.com"
/*获取参数*/
function getParam(url){
    if(!url){
        url = location.search;//获取url�?"?"符后的字�?
    }
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
        }
    }
    return theRequest;
 }
var thisRequest=getParam();
$.cookie("userToken",thisRequest.token, {expires: 7,path: '/'});

var token = $.cookie("userToken");
 //- 头部轮播
var mySwiper = new Swiper('.swiper-container',{
	direction: 'horizontal',
	loop: true,
	autoplay: 3000,
	// 如果需要分页器
	pagination: '.swiper-pagination',
	paginationClickable :true
})

//- 导航效果
$(".olList").on("mouseover", "li",function(){
	$(".rightMenu").show();
	var index=$(this).index();
}).closest(".kindsList").on("mouseleave", function() {
	$(".rightMenu").hide();
});
/*鼠标经过分享显示*/
$("div.contentLeft").on("click",".bottomList .share",function(){
	var shareBox = $(this).closest('.gossipTxt').find(".shareBox");
	if(shareBox.is(":visible")){
		shareBox.hide();
	} else {
		shareBox.show();
	}
})
/*点赞*/
$("div.contentLeft").on("click", ".fabulous", function(){
	if($(this).hasClass("checked")) {
		$(this).removeClass('checked');
	}else{
		$(this).addClass('checked');
	}
})
/*点击评论*/
$("div.contentLeft").on("click",".bottomList .comment",function(){
	$(this).parent(".bottomList").parent(".gossipTxt").css("border-radius","0 15px 0 0");
	$(this).closest('.gossipTxt').siblings('.commentBox').show();
})

/*点击收藏*/
$("div.contentLeft").on("click",".bottomList .collection",function(){
	if($(this).hasClass("selected")) {
		$(this).text("收藏");
		$(this).removeClass('selected');
	}else{
		$(this).text("已收藏");
		$(this).addClass('selected');
	}
})

/*点击跳转个人中心收货地址*/
$(".clickBtn").on("click",".new",function() {
	window.location = "../../view/personCenter/receveAddress.html";
})
/*点击关注*/
$("div.contentLeft").on("click",".cardTop .gzBox",function(){
	if($(this).hasClass("selected")) {
		$(this).text("关注");
		$(this).removeClass('selected');
	}else{
		$(this).text("已关注");
		$(this).addClass('selected');
	}
})
$(function(){
	/*点击个人中心*/
	$("#personCenter").click(function(){
		window.location.href="../personCenter/personIndex.html";
	})
	/*商城*/
	/*点击商城导航*/
	$(".shopNavInner .bigNav li").not('.kinds').on("click",function(){
		$(this).addClass('active').siblings().removeClass('active');
	})

	//- 分页
	$(".paginationOne li").click(function(){
		$(this).addClass("current").siblings().removeClass("current");
	})
	/*点击首页*/
	$(".index").click(function() {
		window.location.href="../shopping/materIndex.html";
	});

	/*点击收藏*/
	$(".menu_04").click(function() {
		window.location.href = "../../view/shopping/myCollect.html";
	})

	/*点击购物车*/
	$(".menu_02").click(function() {
		window.location.href = "../../view/personCenter/shopCar.html";
	})
	/*购物车数量*/
	$.get(shopIp+"/My/cartNumber?userToken="+token,function(data) {
		$(".gwCar i").html(data.data);
	})
	/*点击个人中心供应商、采购商*/
	$(".roles a").click(function() {
		$(this).addClass('current').siblings().removeClass('current');
	})
	/*点击采购商*/
	$(".roles .buyer").click(function() {
		window.location.href = "../../view/personCenter/personIndex.html";
	})
	/*点击供应商*/
	$(".roles .supplier").click(function() {
		$(this).addClass('current').siblings().removeClass('current');
		window.location.href = "../../view/personCenter/personIndex_s.html";
	})
	//- 点击头像进个人资料
	$(".headPortBox  img").click(function() {
		window.location.href = "personData.html";
	})
	/*点击订单里查看评价*/
	$(".allLists").on("click",".lookPj",function() {
		var $this = $(this);
		window.location.href = '../../view/personCenter/lookEvaluation.html?order_id='+$this.closest('.listOne').attr("orderid");
	})

	/*获取顶部固定个人信息*/
	$.get(shopIp+"/user/info?userToken="+token,function(data){
		//console.log(data);
		var msg = data.data;
		$(".gwCar .redFont").html(msg.cart_number);
		$(".headImg img").attr("src",msg.avatar_img);
		$(".squify").html(msg.nice_name)
	})

	// 点击搜索
	$(".searchBox .search-btn").click(function() {
		var searchVal = $(".searchBox .searchTxt").val();
		if(searchVal == "") {
			layer.msg("请输入搜索内容...");
		}else{
			window.location.href = '../../view/shopping/search.html?value='+searchVal;
			$(".searchBox .searchTxt").val("")
		}
	})
	$("body").keydown(function(event) {
		var searchVal = $(".searchBox .searchTxt").val();
		if(event.keyCode == '13') {
			if($(".searchBox .searchTxt").val() == "") {
				layer.msg("请输入搜索内容...");
			}else{
				window.location.href = '../../view/shopping/search.html?value='+searchVal;
				$(".searchBox .searchTxt").val("")
			}
		}
	});
	//- 搜索框下面的商品
	$.post(shopIp+"/search/hotCategory",{
		userToken:token,
		limit:3
	},function(res) {
		var list = res.data;
		for(var i=0;i<list.length;i++) {
			var ele = '<li num='+list[i].name+'><a href="javascript:;">'+list[i].name+'</a></li>'
			$(".shopRig ul").append(ele)
		}
	})
	$(".shopRig").on("click","li",function() {
		window.location.href="search.html?value="+$(this).attr("num");
	});

});
// all
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https'){
   bp.src = 'http://bsh.51adsign.com/Web/pc/dist/view/login.html';
  }
  else{
  bp.src = 'http://bsh.51adsign.com/Web/pc/dist/view/regist.html';
  }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
